﻿using System.Windows.Forms;
using GeoSketch2.Core;

namespace GeoSketch2.Archaeo
{
    /// <summary>
    /// The toolbar button for the excavation unit validation using a polyline
    /// </summary>
    public partial class TBBExcavationUnitPolylineValidate :BaseToolbarButton
    {
        #region Constructor
        /// <summary>
        /// The toolbar button for the excavation unit validation using a polyline
        /// </summary>
        public TBBExcavationUnitPolylineValidate()
        {
            InitializeComponent();
            ToolTipText = "Closes and validate excavation area";
        } 
        #endregion

        #region Events
        /// <summary>
        /// The event on the mouse click on the button
        /// </summary>
        protected override void OnMouseClick(object sender, MouseEventArgs e)
        {
            ((TExcavationUnitCreationPolyline)((TBExcavationUnitCreation)this.Parent).CurrentTool).ClosePolyline();

            ExcavationArea a = new ExcavationArea(((TExcavationUnitCreationPolyline)((TBExcavationUnitCreation)this.Parent).CurrentTool).CurrentPolyline.VerticesPoints, ((Archaeo.DisplayBox)DisplayBox).Viewport.CurrentExcavationArea);

            DisplayBox.Viewport.CurrentLayer = a.AvailableLayers[0];
            ((Archaeo.DisplayBox)DisplayBox).Viewport.CurrentExcavationArea = a;
            ((DrawingForm)this.Parent.Parent).LoadLayers();
            ((DrawingForm)this.Parent.Parent).LoadColors();
            ((DrawingForm)this.Parent.Parent).SetFormTitle();
            ((DrawingForm)this.Parent.Parent).LoadSiteHierarchy();

            ((TBExcavationUnitCreation)this.Parent).CurrentTool.RefreshViewport();

            if (((BaseToolbarButton)Tag).LeftButtonClicked)
            {
                ((BaseToolbarButton)Tag).LeftButtonClicked = false;
                DisplayBox.LeftClicTool = new TNone();
            }
            else if (((BaseToolbarButton)Tag).RightButtonClicked)
            {
                ((BaseToolbarButton)Tag).RightButtonClicked = false;
                DisplayBox.RightClicTool = new TNone();
            }

            ((BaseToolbarButton)Tag).Invalidate();
            DisplayBox.Refresh();
        }
        #endregion
    }
}
